home *** CD-ROM | disk | FTP | other *** search
-
- # include <DialogMgr.h>
- # include <EventMgr.h>
- # include <MenuMgr.h>
- # include <ToolBoxUtil.h>
- # include <Pascal.h>
-
-
- # define nil (0L)
-
- typedef enum
- {
- mDlogRes = 1000,
- aboutAlrtRes /* About... alert resource number */
- };
-
-
- typedef enum /* File menu item numbers */
- {
- showDlog1 = 1,
- showDlog2,
- /* --- */
- quit = 4
- };
-
-
- typedef enum /* Edit menu item numbers */
- {
- undo = 1,
- /* --- */
- cut = 3,
- copy,
- paste,
- clear
- };
-
-
- typedef enum /* dialog item numbers */
- {
- button1 = 1,
- edit1,
- static1,
- radio1,
- radio2,
- radio3,
- check1,
- check2,
- user1
- };
-
-
- DialogPtr mDlog1;
- DialogPtr mDlog2;
- int iconNum1 = 0;
- int iconNum2 = 0;
-
- pascal void DrawIcon (dlog, item)
- DialogPtr dlog;
- int item;
- {
- Handle h;
- Handle itemHandle;
- int itemType;
- Rect itemRect;
-
- GetDItem (dlog, item, &itemType, &itemHandle, &itemRect);
- h = GetIcon (dlog == mDlog1 ? iconNum1 : iconNum2);
- PlotIcon (&itemRect, h);
- }
-
-
- Boolean GetDCtl (dlog, item)
- DialogPtr dlog;
- int item;
- {
- Handle itemHandle;
- int itemType;
- Rect itemRect;
-
- GetDItem (dlog, item, &itemType, &itemHandle, &itemRect);
- return (GetCtlValue (itemHandle));
- }
-
-
- SetDCtl (dlog, item, value)
- DialogPtr dlog;
- int item;
- Boolean value;
- {
- Handle itemHandle;
- int itemType;
- Rect itemRect;
-
- GetDItem (dlog, item, &itemType, &itemHandle, &itemRect);
- SetCtlValue (itemHandle, (int) value);
- }
-
-
- GetDText (dlog, item, str)
- DialogPtr dlog;
- int item;
- StringPtr str;
- {
- Handle itemHandle;
- int itemType;
- Rect itemRect;
-
- GetDItem (dlog, item, &itemType, &itemHandle, &itemRect);
- GetIText (itemHandle, str);
- }
-
-
- SetDText (dlog, item, str)
- DialogPtr dlog;
- int item;
- Str255 str;
- {
- Handle itemHandle;
- int itemType;
- Rect itemRect;
-
- GetDItem (dlog, item, &itemType, &itemHandle, &itemRect);
- SetIText (itemHandle, str);
- }
-
-
- SetDProc (dlog, item, p)
- DialogPtr dlog;
- int item;
- ProcPtr p;
- {
- Handle itemHandle;
- int itemType;
- Rect itemRect;
-
- GetDItem (dlog, item, &itemType, &itemHandle, &itemRect);
- SetDItem (dlog, item, itemType, p, &itemRect);
- }
-
-
- SetDRadio (dlog, item)
- DialogPtr dlog;
- int item;
- {
- DialogPtr partner;
- Handle itemHandle;
- int itemType;
- Rect itemRect;
-
- partner = (DialogPtr) GetWRefCon (dlog);
- SetDCtl (dlog, radio1, item == radio1);
- SetDCtl (dlog, radio2, item == radio2);
- SetDCtl (dlog, radio3, item == radio3);
-
- if (partner == mDlog1)
- iconNum1 = item - radio1;
- else
- iconNum2 = item - radio1;
-
- GetDItem (partner, user1, &itemType, &itemHandle, &itemRect);
- SetPort (partner);
- InvalRect (&itemRect);
- }
-
-
- Event (item, event)
- int item;
- EventRecord *event;
- {
- DialogPtr actor, partner;
- Str255 title;
- Boolean value;
-
- GetPort (&actor);
- partner = (DialogPtr) GetWRefCon (actor);
- switch (item)
- {
- case button1:
- GetDText (actor, edit1, title);
- SetWTitle (partner, title);
- break;
-
- /* set radio buttons */
-
- case radio1:
- SetDRadio (actor, radio1);
- break;
-
- case radio2:
- SetDRadio (actor, radio2);
- break;
-
- case radio3:
- SetDRadio (actor, radio3);
- break;
-
- /* flip check boxes */
-
- case check1:
- value = !GetDCtl (actor, item);
- SetDCtl (actor, item, value);
- if (value == false)
- HideWindow (partner);
- else
- ShowWindow (partner);
- break;
-
- case check2:
- value = !GetDCtl (actor, check2);
- SetDCtl (actor, check2, value);
- ((WindowPeek) partner)->goAwayFlag = (char) (value ? 255 : 0);
- break;
- }
- }
-
-
- Close ()
- {
- DialogPtr actor, partner;
-
- GetPort (&actor);
- partner = (DialogPtr) GetWRefCon (actor);
- HideWindow (actor);
- SetDCtl (partner, check1, false);
- }
-
-
- Clobber ()
- {
- DialogPtr theDialog;
-
- GetPort (&theDialog);
- DisposDialog (theDialog);
- }
-
-
- /*
- File menu handler
- */
-
- DoFileMenu (item)
- int item;
- {
-
- switch (item)
- {
- case showDlog1:
- SelectWindow (mDlog1);
- ShowWindow (mDlog1);
- SetDCtl (mDlog2, check1, true);
- break;
-
- case showDlog2:
- SelectWindow (mDlog2);
- ShowWindow (mDlog2);
- SetDCtl (mDlog1, check1, true);
- break;
-
- case quit:
- SkelWhoa ();
- break;
- }
- }
-
-
- /*
- Handle Edit menu items for text window
- */
-
- DoEditMenu (item)
- int item;
- {
- DialogPtr theDialog;
-
- theDialog = (DialogPtr) FrontWindow ();
- if (((WindowPeek) theDialog)->windowKind != dialogKind)
- return;
-
- switch (item)
- {
- case cut:
- {
- DlgCut (theDialog);
- (void) ZeroScrap ();
- (void) TEToScrap ();
- break;
- }
-
- case copy:
- {
- DlgCopy (theDialog);
- (void) ZeroScrap ();
- (void) TEToScrap ();
- break;
- }
-
- case paste:
- {
- (void) TEFromScrap ();
- DlgPaste (theDialog);
- break;
- }
-
- case clear:
- {
- DlgDelete (theDialog);
- break;
- }
- }
- }
-
-
- /*
- Handle selection of About… item from Apple menu
- */
-
- DoAbout ()
- {
- (void) Alert (aboutAlrtRes, nil);
- }
-
-
- DialogPtr DemoDialog (title, x, y)
- StringPtr title;
- int x, y;
- {
- DialogPtr theDialog;
-
- theDialog = GetNewDialog (mDlogRes, nil, -1L);
- MoveWindow (theDialog, x, y, false);
- SetWTitle (theDialog, title);
- SkelDialog (theDialog, Event, Close, Clobber);
- return (theDialog);
- }
-
-
- main ()
- {
- MenuHandle m;
-
- SkelInit ();
- SkelApple ("\pAbout DialogSkel…", DoAbout);
-
- m = NewMenu (1000, "\pFile");
- AppendMenu (m, "\pShow Dialog 1;Show Dialog 2;(-");
- AppendMenu (m, "\pQuit/Q");
- SkelMenu (m, DoFileMenu, nil);
-
- m = NewMenu (1001, "\pEdit");
- AppendMenu (m, "\p(Undo/Z;(-;Cut/X;Copy/C;Paste/V;Clear");
- SkelMenu (m, DoEditMenu, nil);
-
- mDlog1 = DemoDialog ("\pModeless Dialog 1", 50, 50);
- mDlog2 = DemoDialog ("\pModeless Dialog 2", 150, 200);
- SetWRefCon (mDlog1, mDlog2);
- SetWRefCon (mDlog2, mDlog1);
- SetDText (mDlog1, edit1, "\pModeless Dialog 2");
- SetDText (mDlog2, edit1, "\pModeless Dialog 1");
- SetDProc (mDlog1, user1, DrawIcon);
- SetDProc (mDlog2, user1, DrawIcon);
- SetDCtl (mDlog1, radio1, true);
- SetDCtl (mDlog2, radio1, true);
- SetDCtl (mDlog1, check1, true);
- SetDCtl (mDlog2, check1, true);
- SetDCtl (mDlog1, check2, true);
- SetDCtl (mDlog2, check2, true);
- ShowWindow (mDlog1);
- ShowWindow (mDlog2);
-
- SkelMain ();
- SkelClobber ();
- }
-